clear
cap log close

cd "D:\Dropbox\Work\Research\CreditCardABSRewrite\Draft\ReplicationFiles\Tab_7"

local today = "`c(current_date)'"
log using "Table_07_Log.log", text append

import delimited "Data_Table_07.csv"

* generate year/month
gen ym = ym(year,month)
format ym %tm
tsset ym

* generate indicators for subperiods
generate pre=1 if year<2007
generate cri=1 if year>2006 & year<2010
generate post=1 if year>2009 & year<2021


* Table 7

*****************
* A Tranche
* All
regress riskpremnorm_a quarterendind yearendind	
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_a quarterendind yearendind, lag(4) force
outreg2 using Tab7_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("All") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word slow(200) replace
* 2000-2006
regress riskpremnorm_a quarterendind yearendind	if pre==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_a quarterendind yearendind if pre==1, lag(4) force
outreg2 using Tab7_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2000-2006") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(200) word 
* 2007-2009
regress riskpremnorm_a quarterendind yearendind	if cri==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_a quarterendind yearendind if cri==1, lag(4) force
outreg2 using Tab7_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2007-2009") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(200) word 
* 2010-2020
regress riskpremnorm_a quarterendind yearendind	 if post==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_a quarterendind yearendind if post==1, lag(4) force
outreg2 using Tab7_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2010-2020") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(200) word 


*******************
* B Tranche
* All
regress riskpremnorm_b quarterendind yearendind	
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_b quarterendind yearendind, lag(4) force
outreg2 using Tab7_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("All")  drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word replace
* 2000-2006
regress riskpremnorm_b quarterendind yearendind	if pre==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_b quarterendind yearendind if pre==1, lag(4) force
outreg2 using Tab7_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2000-2006") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 
* 2007-2009
regress riskpremnorm_b quarterendind yearendind	if cri==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_b quarterendind yearendind if cri==1, lag(4) force
outreg2 using Tab7_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2007-2009") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 
* 2010-2020
regress riskpremnorm_b quarterendind yearendind	 if post==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_b quarterendind yearendind if post==1, lag(4) force
outreg2 using Tab7_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2010-2020") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 


*******************
* C Tranche
* All
regress riskpremnorm_c quarterendind yearendind	
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_c quarterendind yearendind, lag(4) force
outreg2 using Tab7_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("All") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word replace
* 2000-2006
regress riskpremnorm_c quarterendind yearendind	if pre==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_c quarterendind yearendind if pre==1, lag(4) force
outreg2 using Tab7_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2000-2006") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 
* 2007-2009
regress riskpremnorm_c quarterendind yearendind	if cri==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_c quarterendind yearendind if cri==1, lag(4) force
outreg2 using Tab7_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2007-2009") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 
* 2010-2020
regress riskpremnorm_c quarterendind yearendind	if post==1
loc AdjR2 = e(r2_a)
newey2 riskpremnorm_c quarterendind yearendind if post==1, lag(4) force
outreg2 using Tab7_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2010-2020") drop(riskpremnorm*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) slow(100) word 

log close